import swaggerJsdoc from 'swagger-jsdoc';
import { Options } from 'swagger-jsdoc';

const options: Options = {
  definition: {
    openapi: '3.0.0',
    info: {
      title: 'AI Bill API',
      version: '1.0.0',
      description: 'AI 账单管理 API 文档',
      contact: {
        name: 'API Support',
        email: 'support@example.com'
      }
    },
    servers: [
      {
        url: 'http://localhost:8000',
        description: '开发环境'
      }
    ],
    components: {
      securitySchemes: {
        bearerAuth: {
          type: 'http',
          scheme: 'bearer',
          bearerFormat: 'JWT'
        }
      },
      schemas: {
        ChatRequest: {
          type: 'object',
          required: ['messages', 'user_id'],
          properties: {
            messages: {
              type: 'array',
              items: {
                type: 'object',
                properties: {
                  role: {
                    type: 'string',
                    enum: ['user', 'assistant', 'system']
                  },
                  content: {
                    type: 'string'
                  }
                }
              }
            },
            user_id: {
              type: 'string',
              description: '用户ID'
            }
          }
        },
        ChatResponse: {
          type: 'object',
          properties: {
            text: {
              type: 'string',
              description: 'AI 回复文本'
            },
            records: {
              type: 'object',
              nullable: true,
              properties: {
                amount: {
                  type: 'number',
                  description: '金额，正数为收入，负数为支出'
                },
                title: {
                  type: 'string',
                  description: '记录标题'
                },
                date: {
                  type: 'string',
                  format: 'date',
                  description: '记录日期'
                }
              }
            }
          }
        },
        RecordRequest: {
          type: 'object',
          required: ['user_id', 'date'],
          properties: {
            user_id: {
              type: 'string',
              description: '用户ID'
            },
            date: {
              type: 'string',
              format: 'date',
              description: '查询日期 (YYYY-MM-DD)'
            }
          }
        },
        Error: {
          type: 'object',
          properties: {
            error: {
              type: 'string',
              description: '错误信息'
            }
          }
        }
      }
    },
    security: [
      {
        bearerAuth: []
      }
    ]
  },
  apis: ['./src/*.ts'] // 扫描所有 TypeScript 文件
};

export const swaggerSpec = swaggerJsdoc(options);
